package com.zsk.shop.controller.gop;

import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.model.params.AddShopGoodsParams;
import com.zsk.shop.model.params.ShopGoodsInfoParam;
import com.zsk.shop.model.results.ShopGoodsInfoResult;
import com.zsk.shop.service.ShopGoodsService;
import com.zsk.shop.service.ShopGoodsSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ljh
 * @create 2021/11/25 14:27
 */
@RestController
@Api(tags = "GOP商品相关")
@RequestMapping("/gop/goods")
public class GopGoodsController {

    @Resource
    private ShopGoodsService shopGoodsService;
    @Resource
    private ShopGoodsSkuService shopGoodsSkuService;

    @NoPermission
    @ApiOperation(value = "商品列表")
    @PostMapping("/getGoodsList.do")
    public BaseResponse<List<ShopGoodsInfoResult>> getGoodsList(@RequestBody ShopGoodsInfoParam param) {
        return shopGoodsService.getGoodsList(param);
    }

    @NoPermission
    @ApiOperation(value = "商品【新增/编辑】新增的时候不传id")
    @PostMapping("/addOrEditGoods.do")
    public BaseResponse addOrEditGoods(@RequestBody AddShopGoodsParams params) {
        return shopGoodsService.addOrEditGoods(params);
    }

    @NoPermission
    @ApiOperation(value = "商品【回显已提交内容（详情）】")
    @GetMapping("/gopGoodsDetailByNo.do")
    public BaseResponse<AddShopGoodsParams> gopGoodsDetailByNo(String goodsNo) {
        if (ToolUtil.isEmpty(goodsNo)) {
            return BaseResponse.error("当前参数异常，请联系客服。");
        }
        return shopGoodsService.gopGoodsDetailByNo(goodsNo);
    }

    @NoPermission
    @ApiOperation(value = "商品【上下架】")
    @GetMapping("/reviewGoods.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "类表中分类id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "letDisable", value = "true变成下架状态,false变成上架状态", dataType = "Boolean", required = true)
    })
    public BaseResponse reviewGoods(Long id, Boolean letDisable) {
        return shopGoodsService.reviewGoods(id, letDisable);
    }

    @NoPermission
    @ApiOperation(value = "商品【删除】")
    @GetMapping("/deleteGoods.do")
    @ApiImplicitParam(name = "id", value = "类表中分类id", dataType = "Long", required = true)
    public BaseResponse deleteGoods(Long id) {
        return shopGoodsService.deleteGoods(id);
    }

    @NoPermission
    @ApiOperation(value = "商品【是否根据标签显示主页】")
    @GetMapping("/updateLabelShow.do")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsNo", value = "商品No", dataType = "String"),
            @ApiImplicitParam(name = "isShow", value = "0 否，1 是", dataType = "Boolean")
    })
    public BaseResponse updateLabelShow(String goodsNo, Boolean isShow) {
        return shopGoodsService.updateLabelShow(goodsNo, isShow);
    }

    @NoPermission
    @ApiOperation(value = "商品【关联标签】")
    @GetMapping("/relatedLabel.do")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsNo", value = "商品No", dataType = "String"),
            @ApiImplicitParam(name = "goodsLabelNo", value = "标签No", dataType = "String")
    })
    public BaseResponse relatedLabel(String goodsNo, String goodsLabelNo) {
        return shopGoodsService.relatedLabel(goodsNo, goodsLabelNo);
    }

//    @NoPermission
//    @ApiOperation(value = "商品【查询该商品的sku信息】")
//    @GetMapping("/goodsSkuList.do")
//    @ApiImplicitParam(name = "goodsNo", value = "商品的编号", dataType = "String", required = true)
//    public BaseResponse<List<ShopGoodsListSkuListResult>> goodsSkuList(String goodsNo) {
//        return shopGoodsService.goodsSkuList(goodsNo);
//    }

//    @PostMapping("/updateGoodsSkuStock.do")
//    @ApiOperation(value = "商品【修改该商品的sku信息（库存）】")
//    public BaseResponse updateGoodsSkuStock(@RequestBody List<ShopGoodsListSkuListResult> list) {
//        return shopGoodsSkuService.updateGoodsSkuStock(list);
//    }

}
